package com.hui.platform.falseworkapi.service.business.user.controller;

import com.hui.platform.falseworkapi.common.security.annotation.SecurityIgnored;
import com.hui.platform.falseworkapi.common.valid.groups.Create;
import com.hui.platform.falseworkapi.common.valid.groups.Update;
import com.hui.platform.falseworkapi.common.web.annotation.ApiResult;
import com.hui.platform.falseworkapi.service.business.user.bo.TbUserBO;
import com.hui.platform.falseworkapi.service.business.user.dto.TbUserLoginDTO;
import com.hui.platform.falseworkapi.service.business.user.dto.TbUserSaveDTO;
import com.hui.platform.falseworkapi.service.business.user.service.TbUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.groups.Default;

/**
 * 用户表 前端控制器
 *
 * @author hui
 * @since 2020-04-14
 */
@Api(tags = "用户表-相关接口")
@ApiResult
@Validated
@RestController
@RequestMapping("/user/tb-user")
public class TbUserController {

    private final TbUserService tbUserService;

    @Autowired
    public TbUserController(TbUserService tbUserService) {
        this.tbUserService = tbUserService;
    }

    //-------接口-------

    @GetMapping("/{id}")
    @ApiOperation("获取一条用户表记录")
    public TbUserBO readById(@ApiParam("用户表Id") @PathVariable @Min(1) Long id) {
        return tbUserService.readById(id);
    }


    @PostMapping("/createOne")
    @ApiOperation("新建一条用户表记录")
    @SecurityIgnored
    public Long createOne(@ApiParam("用户表DTO信息") @RequestBody @Validated({Default.class, Create.class}) TbUserSaveDTO dto) {
        return tbUserService.createOne(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新一条用户表记录")
    public Long updateOne(@ApiParam("用户表Id") @PathVariable @Min(1) Long id,
                          @ApiParam("修改信息") @RequestBody @Validated({Default.class, Update.class}) TbUserSaveDTO dto) {
        return tbUserService.updateOne(id, dto);
    }

    @PostMapping("/userLogin")
    @ApiOperation("用户登录")
    @SecurityIgnored
    public String userLogin(@ApiParam("用户登录") @RequestBody @Validated({Default.class}) TbUserLoginDTO dto) {
        return tbUserService.userLogin(dto);
    }




}

